package com.zyx.javademo.automatic;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Yaxi.Zhang
 * @since 2021/7/21 18:32
 * desc: 原子类型数据案例
 */
public class AtomicDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger();
        final int[] num = {0};
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        try {
                            System.out.println(Thread.currentThread().getName() + ": ato ==> " + atomicInteger.incrementAndGet() +
                                    ",no ato =>" + num[0]++);
                            TimeUnit.MILLISECONDS.sleep(200L);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();
        }
    }
}
